<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
	<meta name="description" content=""/>
	<meta name="author" content=""/>
	<link rel="icon" href="${pageContext.request.contextPath}/static/images/favicon.ico"/>
	<title>信息查询</title>
	<!-- Bootstrap core CSS -->
	<link href="${pageContext.request.contextPath}/static/dist/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
	<link href="${pageContext.request.contextPath}/static/dist/css/bootstrap-grid.css" type="text/css" rel="stylesheet"/>
	<link href="${pageContext.request.contextPath}/static/dist/css/bootstrap-reboot.css" type="text/css" rel="stylesheet"/>
	<link href="${pageContext.request.contextPath}/static/dist/zaddcss/zaddindex.css" type="text/css" rel="stylesheet"/>
	<style type="text/css">
		#serverAddr{
			width:27%;
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:solid rgb(227, 227, 227);
		}
		input[name='okey']{
			width:10%;
			border-radius:5px;
			border:solid rgb(227, 227, 227);
		}
		input[name='otext']{
			width:80%;
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:solid rgb(227, 227, 227);
		}
		input[name='result']{
			width:80%;
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:solid rgb(227, 227, 227);
		}
		input[name='deviceNum']{
			width:130%;
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:solid rgb(227, 227, 227);
		}
		input[name='deviceSN']{
			width:130%;
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:solid rgb(227, 227, 227);
		}
		input[name='deviceOriNum']{
			width:130%;
			border-top:none;
			border-left:none;
			border-right:none;
			border-bottom:solid rgb(227, 227, 227);
		}
		.myRealContext{
			border:solid;
			border-radius:5px;
			padding:10px;
			margin:5px;
		}
	</style>
</head>
<body>
<nav class="navbar navbar-dark bg-dark">
	<a class="navbar-brand" href="#">Never expand</a>
	<!--<div class="collapse navbar-collapse">-->
	<!--<ul class="navbar-nav mr-auto">-->
	<!--<li class="nav-item active">-->
	<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
	<!--</li>-->
	<!--<li class="nav-item">-->
	<a class="nav-link" href="#">Link</a>
	<!--</li>-->
	<!--<li class="nav-item">-->
	<a class="nav-link disabled" href="#">Disabled</a>
	<!--</li>-->
	<!--<li class="nav-item dropdown">-->
	<a class="nav-link dropdown-toggle" href="https://example.com" id="dropdown06" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
	<div class="dropdown-menu" aria-labelledby="dropdown06">
		<a class="dropdown-item" href="#">Action</a>
		<a class="dropdown-item" href="#">Another action</a>
		<a class="dropdown-item" href="#">Something else here</a>
	</div>
	<!--</li>-->
	<!--</ul>-->
	<form class="form-inline my-2 my-md-0" action="#">
		<label>
			<input class="form-control" type="text" placeholder="Search"/>
		</label>
	</form>
	<!--</div>-->
	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample01" aria-controls="navbarsExample01" aria-expanded="false" aria-label="Toggle navigation">
		QA<span class="navbar-toggler-icon"></span>
	</button>
	<div class="collapse navbar-collapse" id="navbarsExample01">
		<p>1234567489123456798</p>
		<p>1234567489123456798</p>
		<p>1234567489123456798</p>
		<p>1234567489123456798</p>
	</div>
</nav>
<main role="main">
	<section class="jumbotron text-center">
		<div class="container">
			<h3 class="jumbotron-heading">常用查询</h3>
		</div>
	</section>
	<div class="album py-3 bg-light">
		<div class="container">
			<div class="container-fluid" style="padding-bottom: auto">
				<div class="myRealContext">
					<p>
						密钥：<input name="okey" type="password" value="abc" placeholder="abc" aria-placeholder="abc"/><br/>
						文字：<input name="otext" type="text" value="1" placeholder="1" aria-placeholder="1"/><br/>
						结果：<input name="result" type="text" value="" placeholder="结果" aria-placeholder="结果" title="结果"/>
					</p>
					<p>
						<input name="gen" type="button" class="btn btn-sm btn-primary" value="加密信息"/>
						<input name="dec" type="button" class="btn btn-sm btn-primary" value="解密信息"/>
					</p>
				</div>
				<div class="myRealContext">
					<p>
						<label for="serverAddr">其它未录入地址（功能未完成）：</label>
						<input name="serverAddr" id="serverAddr" type="text" placeholder="http://1.singbon.com:81" title="服务器地址"/>
					</p>
					<p>
						<label for="serverAddrList">服务器地址：</label>
						<select id="serverAddrList" style="width: 41%">
							<option value="1.singbon.com:81">1.singbon.com:81</option>
							<option value="smartschool.singbon.com:81">smartschool.singbon.com:81</option>
							<option value="a2.4000063966.com:81">a2.4000063966.com:81</option>
							<option value="chongdian.4000063966.com:81">chongdian.4000063966.com:81</option>
							<option value="qisong.4000063966.com:81">qisong.4000063966.com:81</option>
						</select>
					</p>
					<p>
						<input name="getpwd" type="button" class="btn btn-sm btn-primary" value="功能无效"/>
						<input name="loadpwd" type="button" class="btn btn-sm btn-primary" value="获取密码" title="打开新的页面"/>
					</p>
					<p>
						<label>设备号：
							<input name="deviceNum" type="text" value="1" placeholder="1" aria-placeholder="1"/>
						</label><br/>
						<label>序列号：
							<input name="deviceSN" type="text" value="00000000000000000000000000000001" placeholder="00000000000000000000000000000001"/>
						</label><br/>
						<label>原号码：
							<input name="deviceOriNum" type="text" value="1" placeholder="1" aria-placeholder="1"/>
						</label>
					</p>
					<p>
						<input name="loadDeviceInfo" type="button" class="btn btn-sm btn-primary" value="查询设备"/>
						<input name="transToHex" type="button" class="btn btn-sm btn-primary" value="转换格式"/>
					</p>
				</div>
				<div class="myRealContext">
					<a id="aslsServer" href="javascript:void(0)" title="点击复制" data-toggle="tooltip" data-placement="top">39.106.223.169</a><br/>
					<a id="acdzServer" href="javascript:void(0)" title="点击复制" data-toggle="tooltip" data-placement="top">120.79.219.55</a>
				</div>
			</div>
		</div>
	</div>
</main>
<footer class="text-muted" style="margin-top: -10px">
	<div class="container">
		<p class="float-right">
			<a href="#">返回最上</a>
		</p>
		<p>示例页面 &copy; Bootstrap!</p>
		<p>
			<a href="https://github.com/zghnzch">访问我们的主页</a>
		</p>
	</div>
</footer>
<script src="${pageContext.request.contextPath}/static/jquery/3.3.1/jquery-3.3.1.min.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/js/bootstrap.bundle.min.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/zaddjs/encrypt/src/core.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/zaddjs/encrypt/src/cipher-core.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/zaddjs/encrypt/src/tripledes.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/zaddjs/encrypt/src/mode-ecb.js"></script>
<script src="${pageContext.request.contextPath}/static/dist/zaddjs/copyContent/copyContent.js"></script>
<!--方法区-->
<script type="text/javascript">
	//加密的私钥 let 和 Var 有什么区别？
	// DES  加密
	function encryptByDES(key,message){
		// key = $('input[name=okey]').val();
		//把私钥转换成16进制的字符串
		let keyHex = CryptoJS.enc.Utf8.parse(key);
		//模式为ECB padding为Pkcs7
		let encrypted = CryptoJS.DES.encrypt(message,keyHex,{
			mode:CryptoJS.mode.ECB,
			padding:CryptoJS.pad.Pkcs7
		});
		//加密出来是一个16进制的字符串
		return encrypted.ciphertext.toString();
	}
	//DES  ECB模式   解密
	function decryptByDESModeEBC(key,ciphertext){
		//把私钥转换成16进制的字符串
		let keyHex = CryptoJS.enc.Utf8.parse(key);
		//把需要解密的数据从16进制字符串转换成字符byte数组
		let decrypted = CryptoJS.DES.decrypt({
			ciphertext:CryptoJS.enc.Hex.parse(ciphertext)
		},keyHex,{
			mode:CryptoJS.mode.ECB,
			padding:CryptoJS.pad.Pkcs7
		});
		//以utf-8的形式输出解密过后内容
		return decrypted.toString(CryptoJS.enc.Utf8);
	}
</script>
<!--jquery 初始化-->
<script type="text/javascript">
	//<![CDATA[
	$(function(){
		$('[data-toggle="tooltip"]').tooltip();
		/*元素定义---------------------------------*/
		// region 元素定义
		// region input标签
		//密钥
		let eleInputNameOkey = $("input[name='okey']");
		//需要处理的文字
		let eleInputNameOtext = $("input[name='otext']");
		//处理结果
		let eleInputNameResult = $("input[name='result']");
		//设备号码
		let eleInputNameDeviceNum = $("input[name='deviceNum']");
		//设备SN
		let eleInputNameDeviceSN = $("input[name='deviceSN']");
		//原号码
		let eleInputNameDeviceOriNum = $("input[name='deviceOriNum']");
		// endregion输入框
		// region 按钮
		/*按钮---------------------------------*/
		//复制文字
		let eleBtnCopy39106223169 = $("input[name='copy39106223169']");
		//复制文字
		let eleBtnCopy1207921955 = $("input[name='copy1207921955']");
		//查询设备所属信息
		let eleBtnLoadDeviceInfo = $("input[name='loadDeviceInfo']");
		//加密
		let eleBtnGen = $("input[name='gen']");
		//解密
		let eleBtndec = $("input[name='dec']");
		//直接获取密码
		let eleBtnGetpwd = $("input[name='getpwd']");
		//新页面获取密码
		let eleBtnLoadpwd = $("input[name='loadpwd']");
		//　设备号码转换十六进制
		let eleBtnTransToHex = $("input[name='transToHex']");
		// endregion 按钮
		// region 段落文字
		/*段落文字---------------------------------*/
		// let elePIdSlsServer = $('#slsServer');
		// let elePIdCdzServer = $('#cdzServer');
		// endregion 段落文字
		// region a 标签
		/*a 标签---------------------------------*/
		let eleAIdSlsServer = $("#aslsServer");
		let eleAIdCdzServer = $("#acdzServer");
		// endregion a 标签
		// region input标签
		let eleSelectIdserverAddrList = $("#serverAddrList");
		// endregion input标签
		// endregion 元素定义
		/*元素click---------------------------------*/
		// region 元素click
		// btn 加密
		eleBtnGen.click(function(){
			//需要加密的内容
			let key = eleInputNameOkey.val();
			let otext = eleInputNameOtext.val();
			console.log("key:"+key);
			console.log("otext:"+otext);
			// let enResult = encryptByDES(key,otext);

			let enResult = encryptByDES('ycsty',otext);
			console.log("enResult:"+enResult);
			eleInputNameResult.val(enResult);
		});
		//解密
		eleBtndec.click(function(){
			let key = $('input[name=okey]').val();
			let otext = $("input[name='otext']").val();
			let deResult = decryptByDESModeEBC(key,otext);
			eleInputNameResult.val(deResult);
		});
		// btn 获取密码
		eleBtnGetpwd.click(function(){
			let eleSelected = $('#serverAddrList option:selected');
			let selectedval = eleSelected.val();
		});
		// btn 新页面获取密码
		eleBtnLoadpwd.click(function(){
			//需要加密的内容
			let key = eleInputNameOkey.val();
			let otext = eleInputNameOtext.val();
			let enResult = encryptByDES(key,otext);
			let url = "http://"+$('#serverAddrList option:selected').val();
			url = url+"/s/suf.do?s="+enResult;
			window.open(url);
		});
		// btn 新页面获取设备信息
		eleBtnLoadDeviceInfo.click(function(){
			let valDeviceNum = eleInputNameDeviceNum.val();
			let url = "http://"+$('#serverAddrList option:selected').val();
			// url = url + "/s/suf.do?s=" + enResult;
			url = url+"/s/s.do?s="+valDeviceNum;
			window.open(url);
		});
		// a sls 标签点击复制
		eleAIdSlsServer.click(function(){
			let targetId = eleAIdSlsServer.attr('id');
			let copyContext = eleAIdSlsServer.text();
			let isCopySuccess = copy(targetId,'innerText');
			let tooltipText = copyContext;
			if(isCopySuccess===1){
				tooltipText += "复制成功"
			}
			else if(isCopySuccess===0){
				tooltipText += "复制失败"
			}
			else{
				tooltipText += "复制方法异常"
			}
			eleAIdSlsServer.attr('data-original-title',tooltipText).tooltip('update').tooltip('show');
		});
		// a sls 标签点击复制
		eleAIdCdzServer.click(function(){
			let targetId = eleAIdCdzServer.attr('id');
			let copyContext = eleAIdCdzServer.text();
			let isCopySuccess = copy(targetId,'innerText');
			let tooltipText = copyContext;
			if(isCopySuccess===1){
				tooltipText += "复制成功"
			}
			else if(isCopySuccess===0){
				tooltipText += "复制失败"
			}
			else{
				tooltipText += "复制方法异常"
			}
			eleAIdCdzServer.attr('data-original-title',tooltipText).tooltip('update').tooltip('show');
		});
		//设备号码转换十六进制
		eleBtnTransToHex.click(function(){
			let valDeviceNum = eleInputNameDeviceNum.val();
			var c = parseInt(valDeviceNum).toString(16).toUpperCase();
			while(c.length<32){
				c = "0"+c;
			}
			eleInputNameDeviceSN.val(c);
		});
		/*元素监听 on---------------------------------*/
		//
		eleInputNameDeviceNum.on('input',function(){
			let valDeviceNum = eleInputNameDeviceNum.val();
			let c = parseInt(valDeviceNum).toString(16).toUpperCase();
			while(c.length<32){
				c = "0"+c;
			}
			eleInputNameDeviceSN.val(c);
		});
		//
		eleInputNameDeviceSN.bind("input",function(){
			let valDeviceSN = eleInputNameDeviceSN.val();
			var ten = parseInt(valDeviceSN,16);
			eleInputNameDeviceOriNum.val(ten);
		});
		//
		eleInputNameDeviceSN.on('mouseover',function(){
			let valDeviceSN = eleInputNameDeviceSN.val();
			var ten = parseInt(valDeviceSN,16);
			eleInputNameDeviceOriNum.val(ten);
		});
		// endregion 元素click
	});
	//]]>
</script>
</body>
</html>
